
import amCharts
import diskUsageResource
from whiff import resolver
from whiff.middleware import displayTraceback

def application(directory):
    diskUsageFinder = diskUsageResource.du(directory)
    rootApplication = resolver.moduleRootApplication("/", amCharts,
                                                     exception_middleware=displayTraceback.__middleware__,
                                                     on_not_found=None, # show traceback (could comment)
                                                     )
    rootApplication.registerResourceFinder(prefix="du", finder=diskUsageFinder)
    return rootApplication

def serve(directory, port=8888, host="localhost"):
    import wsgiref.simple_server
    app = application(directory)
    port = int(port)
    srv = wsgiref.simple_server.make_server(host, port, app)
    print "serving whiff disk usage for", directory
    print "as http on host", host, "port", port
    print "start page at http://localhost:8888/diskUsage"
    srv.serve_forever()

if __name__=="__main__":
    import sys
    serve(sys.argv[1])
